package cn.edu.scau.cmi.suyaoxing.client;

import cn.edu.scau.cmi.suyaoxing.factory.*;
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;


public class FactoryClient extends Application{
   public static void main(String[] args) {
       launch(args);
    }
   private String[] insur= {"身体受伤","汽车损坏","人员伤亡","综合险"};
   private int num;
   private InsuranceFactory infac=null;
   @Override
   public void start(Stage primaryStage) {
       GridPane gridpane=new GridPane();
       gridpane.setAlignment(Pos.CENTER);
       gridpane.setHgap(1);
       gridpane.setVgap(1);
       
       Label lb1=new Label("姓名:");
       Label lb2=new Label("学号:");
       Label lb3=new Label("请选择保险:");
       Label lb4=new Label("世贤");
       Label lb5=new Label("11111");
      
       ComboBox<String> cbo=new ComboBox<>();
       ObservableList<String> items=FXCollections.observableArrayList(insur);
       cbo.getItems().addAll(items);
       
       Image image=new Image("/res/factory_1.jpg");
       ImageView imageview=new ImageView(image);
       imageview.setFitHeight(200);
       imageview.setFitWidth(400);
       
       TextField tf=new TextField();
       Button bt1=new Button("显示保险信息");
       
       gridpane.add(imageview, 0, 0,1,8);
       gridpane.add(lb1, 1, 0);
       gridpane.add(lb4, 2, 0);
       gridpane.add(lb2, 3, 0);
       gridpane.add(lb5, 4, 0);
       gridpane.add(lb3, 2, 3);
       gridpane.add(cbo, 3, 3);
       gridpane.add(bt1, 3, 6);
       gridpane.add(tf, 1, 7);
       
       
       bt1.setOnAction(new EventHandler<ActionEvent>() {
           @Override
           public void handle(ActionEvent event) {
        	   num=items.indexOf(cbo.getValue());
        	   switch(num) {
        	   case 0:infac=new BodyInjureFactory();break;
        	   case 1:infac=new CollisionFactory();break;
        	   case 2:infac=new PersonInjureFactory();break;
        	   case 3:infac=new ComFactory();break;
        	   }
        	   if(infac!=null) {
        		   Insurance in=infac.getInstance();
        		   tf.setText(in.getInsuranceInfo());
        	   }
           }
       });
       
       Scene scene=new Scene(gridpane,1000,500);
       primaryStage.setTitle("实验四工厂方法");
       primaryStage.setScene(scene);
       primaryStage.show();
    }
}
